package com.fastwire.carriere.inventory.vo;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;

import com.fastwire.carriere.common.mapper.NENameMapper;
import com.fastwire.carriere.common.mapper.TPNameMapper;
import com.fastwire.carriere.common.util.StringUtil;
import com.fastwire.carriere.dao.DAOException;
import com.fastwire.carriere.dao.DAOFactory;
import com.fastwire.carriere.dao.NetworkInventoryDao;
import com.fastwire.carriere.inventory.entity.FDFr;
import com.fastwire.carriere.inventory.entity.NetworkElement;
import com.fastwire.carriere.inventory.entity.NetworkEntityUserSpecificInfo;

// TODO: Auto-generated Javadoc
/**
 * The Class FDFrVo.
 */
@Root(name = "FDFR")
public class FDFrVo {

	/** The native ems name. */
	@Attribute
	private String nativeEmsName;

	/** The name. */
	@Attribute
	private String name;

	/** The aend tp. */
	@Attribute
	private String aendTp;

	/** The zend tp. */
	@Attribute
	private String zendTp;

	/** The is flexible. */
	@Attribute(required = false)
	private String isFlexible;

	/** The administrative state. */
	@Attribute(required = false)
	private String administrativeState;

	/** The fdfr type. */
	@Attribute(required = false)
	private String fdfrType;

	/** The fdfr state. */
	@Attribute(required = false)
	private String fdfrState;

	/** The ingress tmd ref. */
	@Attribute(required = false)
	private String ingressTmdRef;

	/** The egress tmd ref. */
	@Attribute(required = false)
	private String egressTmdRef;

	@Attribute(required = false)
	private String remarks;

	@Attribute(required = true)
	private String type = "FDFr";

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	/**
	 * Instantiates a new fD fr vo.
	 */
	public FDFrVo() {
		super();
	}

	/**
	 * Instantiates a new fD fr vo.
	 * 
	 * @param fdfr
	 *            the fdfr
	 */

	public FDFrVo(FDFr fdfr) {
		name = fdfr.getName();
		nativeEmsName = fdfr.getEmsNativeName();
		isFlexible = fdfr.getIsFlexible();

		administrativeState = fdfr.getAdministrativeState();
		fdfrState = fdfr.getFdfrState();
		fdfrType = fdfr.getFdfrType();

		try {
			NetworkElement ne = NENameMapper.getNEbyU2kName(name);

			if (fdfr.getAendTp() != null) {
				aendTp = TPNameMapper.getReadableTpName(fdfr.getAendTp()
						.getName(), fdfr.getAendTp().getType(), ne);
			}

			if (fdfr.getZendTp() != null) {
				zendTp = TPNameMapper.getReadableTpName(fdfr.getZendTp()
						.getName(), fdfr.getZendTp().getType(), ne);
			}

			ingressTmdRef = fdfr.getAendTp().getIngressTmdRef();
			egressTmdRef = fdfr.getAendTp().getEgressTmdRef();
			//Commented as it queries for every FDFR and is not necessary			
			/*
			if (!StringUtil.isEmptyString(nativeEmsName)) {

				NetworkInventoryDao inventoryDao = DAOFactory.getInstance()
						.getNetworkInventoryDao();
				NetworkEntityUserSpecificInfo info = inventoryDao
						.getNetworkEntityUserSpecificInfobyNameAndType(
								nativeEmsName, FDFr.class.getSimpleName());
				if (info != null) {
					remarks = info.getRemark();
				}
			}*/

		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}

	}

	/**
	 * Gets the native ems name.
	 * 
	 * @return the native ems name
	 */
	public String getNativeEmsName() {
		return nativeEmsName;
	}

	/**
	 * Sets the native ems name.
	 * 
	 * @param nativeEmsName
	 *            the new native ems name
	 */
	public void setNativeEmsName(String nativeEmsName) {
		this.nativeEmsName = nativeEmsName;
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the aend tp.
	 * 
	 * @return the aend tp
	 */
	public String getAendTp() {
		return aendTp;
	}

	/**
	 * Sets the aend tp.
	 * 
	 * @param aendTp
	 *            the new aend tp
	 */
	public void setAendTp(String aendTp) {
		this.aendTp = aendTp;
	}

	/**
	 * Gets the zend tp.
	 * 
	 * @return the zend tp
	 */
	public String getZendTp() {
		return zendTp;
	}

	/**
	 * Sets the zend tp.
	 * 
	 * @param zndTp
	 *            the new zend tp
	 */
	public void setZendTp(String zndTp) {
		this.zendTp = zndTp;
	}

	/**
	 * Gets the checks if is flexible.
	 * 
	 * @return the checks if is flexible
	 */
	public String getIsFlexible() {
		return isFlexible;
	}

	/**
	 * Sets the checks if is flexible.
	 * 
	 * @param isFlexible
	 *            the new checks if is flexible
	 */
	public void setIsFlexible(String isFlexible) {
		this.isFlexible = isFlexible;
	}

	/**
	 * Gets the administrative state.
	 * 
	 * @return the administrative state
	 */
	public String getAdministrativeState() {
		return administrativeState;
	}

	/**
	 * Sets the administrative state.
	 * 
	 * @param administrativeState
	 *            the new administrative state
	 */
	public void setAdministrativeState(String administrativeState) {
		this.administrativeState = administrativeState;
	}

	/**
	 * Gets the fdfr type.
	 * 
	 * @return the fdfr type
	 */
	public String getFdfrType() {
		return fdfrType;
	}

	/**
	 * Sets the fdfr type.
	 * 
	 * @param fdfrType
	 *            the new fdfr type
	 */
	public void setFdfrType(String fdfrType) {
		this.fdfrType = fdfrType;
	}

	/**
	 * Gets the fdfr state.
	 * 
	 * @return the fdfr state
	 */
	public String getFdfrState() {
		return fdfrState;
	}

	/**
	 * Sets the fdfr state.
	 * 
	 * @param fdfrState
	 *            the new fdfr state
	 */
	public void setFdfrState(String fdfrState) {
		this.fdfrState = fdfrState;
	}

	/**
	 * Gets the ingress tmd ref.
	 * 
	 * @return the ingress tmd ref
	 */
	public String getIngressTmdRef() {
		return ingressTmdRef;
	}

	/**
	 * Sets the ingress tmd ref.
	 * 
	 * @param ingressTmdRef
	 *            the new ingress tmd ref
	 */
	public void setIngressTmdRef(String ingressTmdRef) {
		this.ingressTmdRef = ingressTmdRef;
	}

	/**
	 * Gets the egress tmd ref.
	 * 
	 * @return the egress tmd ref
	 */
	public String getEgressTmdRef() {
		return egressTmdRef;
	}

	/**
	 * Sets the egress tmd ref.
	 * 
	 * @param egressTmdRef
	 *            the new egress tmd ref
	 */
	public void setEgressTmdRef(String egressTmdRef) {
		this.egressTmdRef = egressTmdRef;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

}
